<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
        &times;
    </button>
    <h4 class="modal-title" id="myModalLabel">
        欢迎，请先登录
    </h4>
</div>
<div class="modal-body">
    <form action="" method="post">
        <div class="form-group">
            <h4>
                <a href="#">
                    <img src="__PUBLIC__/img/shoping/yh.png" width="20px" height="20px" alt="">
                    开始登录
                </a>
            </h4>
            <input type="text" class="form-control" name="telephone" id="telephone" placeholder="手机号" />
            <input type="password" class="form-control" name="password" id="password" placeholder="密码" />
            <input type="text" class="form-control" name="img_verify" id="img_verify" placeholder="图片验证码" style="width: 70%;float: left;margin-top: 0px;" />
            <span style="float: left;margin-left: 4%;width: 25%;"><img style="float:left;margin-top:5px;height:30px; width:50px" src='./index.php/shop/getImageVerify' onclick="javascript:$(this).attr('src', './index.php/shop/getImageVerify?'+Math.random());" /></span>
            <div class="checkbox" style="float: left;width: 100%;">
                <label style="float: left;">
                    <input type="checkbox" name="">
                    下次自动登录
                </label>
                <label style="float: right;">
                    <a href="/cn/forgot-password.html">
                        忘记密码？
                    </a>
                </label>
            </div>
            <input class="form-cont" id="confirm" value="登录" type="button">
            <p class="action-forgot-password ">
                没有账号？
                <a class="action-link" href="{:U('shop/register')}">
                    立即注册
                </a>
            </p>
        </div>
    </form>
</div>
<!-- <div class="modal-footer">
    <button id="btnAgree" type="button" class="btn btn-primary">确认</button>
    <button id="btnCancel" type="button" class="btn btn-default">取消</button>
</div> -->
<script type="text/javascript">
$(function() {

     $('#confirm').on('click',function() {
        var telephone = $('#telephone').val();
        var img_verify = $('#img_verify').val();
        var password = $('#password').val();
        if (telephone == '' || telephone == null) {
            alert('请输入正确的手机号码');
            $("#telephone").focus();
            return false;
        }else{
            if (!checktelephone(telephone)) {
                alert('请输入正确的手机号码');
                return false;
            }
        }
        if (password == '' || password == null) {
            alert('请输入您的密码');
            $("#password").focus();
            return false;
        }
        if (img_verify == '' || img_verify == null) {
            alert('请输入图片验证码');
            $("#img_verify").focus();
            return false;
        }
        
        if (password != '' && password != null) {
            // $('form').submit();
            $.ajax({
                url:'{:U('shop/login')}',
                data: {
                    telephone:telephone,
                    password:password,
                    img_verify:img_verify
                },
                type:'post',
                dataType:'json',
                success:function(data){
                    if(data.status == 1){
                        alert('登录成功！');
                        // window.history.back(-1);
                        window.location.reload();
                    }else{
                        alert(data.info);
                        return false;
                    }
                },
                error:function(data){
                    alert(data.info);
                    return false;
                }
            });
        } else {
            alert('请重新检查您的密码');
        }
    });
    function checktelephone(telephone) {
        var filter  = /^1[3578][0-9]{9}$/;
        if (filter.test(telephone)){
            return true;
        }else{
            return false;
        }
    }

    $("#btnAgree").click(function(){
        var address = $('#sel_address_id').find("option:selected").text();
        var address_id = $('#sel_address_id').val();
        $('#address_content').html(address);
        $('#address_id').val(address_id);
        $("#Modal1").modal("hide");
    })
    $("#btnCancel").click(function(){
        $("#Modal1").modal("hide");
    })
});
</script>